﻿using UnityEngine;

namespace SoarD.Pandora
{
	public class PdrUtil
	{
		/// <summary>
		/// Checks the missing component.只检查组件丢失
		/// </summary>
		/// <returns>返回丢失组件的日志</returns>
		/// <param name="go">Go.</param>
		public static string CheckMissingComponent(GameObject go)
		{
			string strLog = "";
			foreach (Component component in go.GetComponents(typeof(Component)))
			{
				if (component == null)
				{
					strLog += "Missing Component in : " + GetFullPathOfGO (go) + "\n";
				}
//				else
//				{
//					CheckMissingComponent(go, component);
//				}
			}
			for (int i = 0; i < go.transform.childCount; i++)
			{
				Transform child = go.transform.GetChild (i);
				if (child != null)
				{
					strLog +=  CheckMissingComponent(child.gameObject);
				}
			}
			return strLog;
		}

		public static string GetFullPathOfGO(GameObject go)
		{
			string path = "";
			Transform parent = go.transform;
			while(parent != null)
			{
				path += "/";
				path += parent.name;
				parent = parent.parent; 
			}
			return path;
		}
	}
}

